<!DOCTYPE html>
<html>
<head>
<title>Git分享--解决你遇到90%的Git问题 - 幕布</title>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit"/>
<meta name="author" content="mubu.com"/>
</head>
<body style="margin: 50px 20px;color: #333;font-family: 'Helvetica Neue','Hiragino Sans GB','WenQuanYi Micro Hei','Microsoft Yahei',sans-serif;">
<div class="export-wrapper"><div style="font-size: 24px; padding: 20px 15px 0;"><div style="padding-bottom: 10px">Git分享--解决你遇到90%的Git问题</div><div style="background: #e5e6e8; height: 1px; margin-bottom: 20px;"></div></div><ul style="list-style: disc outside;"><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" color="#333333" heading="1" style="color: rgb(51, 51, 51); line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">一.“版本控制系统”问世</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.什么是"版本控制"？确保不同人所编辑的同一东西能集体得到更新，并在必要时候可以对没一个修改状态进行：查看、恢复</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.为什么会有"版本控制系统"？==&gt;"工具"的产生都是为了解决"生产"上的烦恼==&gt;</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">各自复制+重命名版本号：名字混乱(起名字真的很难起)、被覆盖了就"完蛋"了、不能协作</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">本地版本系统:RCS【类似"系统补丁"，在硬盘上保存"差集"，回退时进行大量计算比较得出不同】--不能协作，个人电脑容易"犯傻"，遇到了问题：如何让不同人在不同系统上的开发者协同工作？</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">集中式版本管理【有一个单一的集中管理的服务器，保存所有文件的修订版本，而协同工作的人们都通过客户端连到这台服务器，取出最新的文件或者提交更新】：CVS、SVN</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">分布式版本管理【客户端并不只提取最新版本的文件快照，而是把代码仓库完整地镜像下来。 这么一来，任何一处协同工作用的服务器发生故障，事后都可以用任何一个镜像出来的本地仓库恢复，更进一步，许多这类系统都可以指定和若干不同的远端代码仓库进行交互】：Git、Bazaar</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.为什么会有"Git"?==&gt;2005年，BitKeeper的商业公司与Linux内核开源社区的合作关系结束，Linux之父一气之下开发了自己的版本控制系统：速度、安全、简单的设计、对非线性开发模式的强力支持(允许成千上万的分支并行开发)、完全分布式、有能力高效的管理类似Linux内核一样的超大规模项目(速度与数据量)</span></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" color="#333333" heading="1" style="color: rgb(51, 51, 51); line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">二.Git与SVN的比较</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">一).优缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN优缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">优点：1.相比老式版本控制，解决了协同合作问题，让每个人在一定的程度上知道其他人的工作；2.权限管理方便，能做到非常"精细"的分配；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.中央服务器单点故障，如果中央服务器磁盘发生故障，且没做过备份或者备份得不及时的话，还会有丢失数据的风险,最坏的情况是彻底丢失整个项目的所有历史记录【不能保证所有的数据都已经有人提取出来】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.提交必须有网络连接--非本地版本库；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.权限不支持分支继承；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4.迁移量大【仍然是记录版本间的"差异"】；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">5.SVN原理上只关心文件内容的具体差异--进行还原的时候需要反复计算差异得到结果</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">6.SVN的工作区和版本库物理上分开，只能通过http、https、svn等协议访问"某一历史状态下的快照"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">7.服务器压力大，数据库容量暴增</span></li></ul></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git优缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">优点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.只要你愿意，你的"仓库"就是所有人的仓库；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.从技术上讲：Git可能永远做不到类似SVN的路径授权(精细授权)--公司对代码库进行合理拆分，按库授权</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.每一次提交都是对代码仓库的完整备份--快照模式==&gt;所以Git在切换操作上能如此的"速度"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4.工作区与本地仓库如影随行，不受"外界"干扰--你做你的，我做我的，必要的时候再提交到远程仓库合并更新；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">5.只要有一个人的代码是最新的，那么就不会丢失掉"所有提交记录</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">6.Git使用SHA-1散列哈希值作为全球唯一的版本号，这样的好处：①对于一个分布式版本控制系统，每个人每次提交后形成的版本号都不会出现重复；②保证了数据的完整性【哈希值是根据文件内容+目录结构计算出来的，且这一数据验证是被放在Git的底层，所以想要瞒过Git进行操作几乎是不可能】</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">缺点：代码保密性差，开发者可以克隆所有代码和版本信息</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">二).区别：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN的工作区中"每一个目录"都包含一个名为.svn的控制隐藏目录，该目录的作用：①标识"当前工作区"和"版本库检出时"的状态关系；②包含了一份"检出时"的原始拷贝，当比较文件改动差异&amp;&amp;本地改动回退时，可直接参考原始拷贝进行操作不需要联网；③在目录下按文件搜索时，.svn下的文件原始拷贝会导致多出一倍的搜索时间和搜索结果；④.svn很容易在集成时引入产品中，从而导致Web服务器安全隐患</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git只在工作区的根目录下有"唯一"的.git的子目录，这个.git目录就是"完整的版本库"本身,存放了所有的元数据与对象数据【一旦你删除，就是破坏了整个版本库】，除了和其他人交换数据外，任何版本库相关的操作都在本地完成【本地操作，避免了冗长的网络延迟--速度快】；版本库"可以"脱离工作区而存在，成为"赤裸"版本库--搭建git仓库(git init --bare)，但是工作区"不可以"脱离版本库而存在</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">思考：一旦你.git，就是破坏了整个版本库，那么如何保证Git数据安全呢？方法①【本地的数据镜像化】：在A磁盘分区中创建"赤裸"版本库( --bare) ，然后在另B磁盘分区中克隆A中的版本库作为工作区，把B工作区的提交定时的PUSH到A分区的版本库；方法②：其他人定时clone项目并pull备份</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN的全局版本好相较于CVS的每个文件都独立维护一套版本号相比，是一个非常大的进步，看似简单的进步实际标明：SVN提供支持"事务提交"--每一个"事务处理"都具备整个版本库全局唯一的版本号，但SVN的版本号是"连续"的，可以预判到下一个版本号；Git的版本号就更"碉堡"了，是全球唯一的(SHA-1碰撞+数据长度一致的情况下才会有问题)，Git每一次提交，会对"文件内容和目录结构"计算出一个SHA-1散列哈希值【40位的十六进制字符串】作为版本号，这也增加了预判下一个版本号的难度(几乎是不可能);--【Git 一般使用从左面开始的7位字串作为简化版本号，只要该简化的版本号不产生歧义（只要不会出现重复的，你也可以使用更短的版本号）即可】【关于哈希碰撞问题，Git的解决方法：How would Git handle a SHA-1 collision on a blob?：<a class="content-link" target="_blank" rel="noreferrer" href="https://stackoverflow.com/questions/9392365/how-would-git-handle-a-sha-1-collision-on-a-blob/9392525#9392525" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://stackoverflow.com/questions/9392365/how-would-git-handle-a-sha-1-collision-on-a-blob/9392525#9392525</a>】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN可以将整个库检出到工作区，也可以将某个目录检出到工作区(每个文件夹里都有一个.svn)，对于一个庞大、臃肿的版本库用户来说，部分检出是非常方便的，但是Git只能全部检出，不支持按照目录进行部分检出【只有在根目录下有一个.git文件，但是Git可以通过子模块处理版本库模块化的问题从而解决这个问题】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN的分支是通过svn cp命令，即：带历史的拷贝(但这是一种廉价拷贝：并不是拷贝所有数据，而是建立一个已存在目录树的入口，这也导致了SVN的分支之间没有完全"隔离")；Git中的分支实际上仅仅是一个包含所指对象校验和的文件，因此创建和销毁一个分支都非常的廉价(Git新建一个分支其实就是向一个文件写入41个字节：40位版本号+1个换行符)！Git的分支是完全隔离的；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN不会记录任何合并操作，当你提交本地修改，版本库并不能判断改提交来源于svn merge还是你手工修改之后svn commit的；而Git则可以很清晰的分辨出你的提交来源是：git commit 还是 git merge 亦或是git push</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SVN一旦完成向服务器的数据提交，就没法从客户端追回，只能在后续提交中覆盖修正【集中式】;Git是分布式的，代码库允许任意的修改和丢弃【git rebase 、 git filter-branch、git reset】，因此Git可以修改和重构历史提交，且非常灵活，但是SVN修改历史提交只能由管理员来完成(在服务端进行撤销和修改，代价大)，但SVN能修改任意节点的提交说明，而Git只能修改最后一个commit的信息，且修改后将产生一个新的提交(commit号会变)；</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读《SVN与Git的比较》系列：<a class="content-link" target="_blank" rel="noreferrer" href="http://blog.sina.com.cn/s/blog_765348af0102uyo9.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://blog.sina.com.cn/s/blog_765348af0102uyo9.html</a></span></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">三.Git 协议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">一)、本地协议【Local Protocol】==&gt;【cd xxx】git init --bare test.git ==&gt; git clone /xxx/test.git </span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.优点：1).简单；2).直接使用现有文件权限和网络访问权限；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.缺点：1).配置共享文件系统难；2).不方便多位置访问;3)."远程磁盘"方式访问，配置不便，访问慢；4).文件协议不保护仓库意外的损坏</span></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">二)、"哑"HTTP协议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.Git 1.6.6版本之前只有一个方式可用，比较简单且通常是"只读模式"，而且是谁都可以读～</span></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">三)、"智能"HTTP协议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">优点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.Git 1.6.6版本引入；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.运行在标准的HTTP/S端口上并且可以使用各种HTTP验证机制</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.即支持 "git://" 协议一样设置匿名服务；也可以像SSH协议一样提供传输时授权和加密数据</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4.目前使用最流行的：可用性强</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">不同访问方式，只需要一个URL以及服务器只在需要授权时提示输入授权信息</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">相比SSH协议，设置简单，免去设置公钥</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">HTTP协议传输也非常的快和高效</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">可以在HTTPS协议上提供只读版本库的服务；甚至可以让客户端使用制定的SSL证书</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">HTTP/S协议被广泛使用，一般的企业防火墙都会允许这些端口的数据通过</span></li></ul></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">架设HTTP/S协议的服务端比SSH协议难；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">如果你在HTTP上使用需授权的推送，管理凭证会比使用SSH秘钥认证麻烦</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">四）、SSH协议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SSH协议是一个需要验证授权【采用公私密钥】的、普遍、建设简单、使用简单的协议；</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">git clone <a class="content-link" target="_blank" rel="noreferrer" href="ssh://user@server/project.git" style="text-decoration: underline; opacity: 0.6; color: inherit;">ssh://user@server/project.git</a> 或[scp方式] git clone user@server:project.git</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">优点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.建设SSH协议访问服务简单，而且大多数环境下已经支持SSH访问</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.SSH访问安全--所有传输数据都要经过授权和加密</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.SSH协议很高效，传输前会尽量的亚索数据【其他的协议也会】</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">缺点：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.不能匿名访问【不利于项目开源】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">如果你要同事提供匿名只读访问和SSH协议，那么需要搭建SSH服务和架设一个可以让他人访问的服务</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">生成SSH公钥：ssh-keygen -t 加密方式[rsa|dsa] -C "youremai@email.com"：<a class="content-link" target="_blank" rel="noreferrer" href="https://help.github.com/articles/connecting-to-github-with-ssh/" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://help.github.com/articles/connecting-to-github-with-ssh/</a></span></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">五）、git协议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">包含在Git里的一个特殊的守护进程，监听9418端口，但是访问无需任何授权，没有任何安全措施【要么所有人都可以访问，要么谁也不能访问，而且只要有人知道项目URL都可以向项目推送数据】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">优点：Git协议是Git使用的网络传输协议中最快的</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">缺点：缺乏授权机制；架设繁杂困难；监听端口为非标准端口，一般企业防火前不会开放；</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v2/Git-内部原理-传输协议" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/book/zh/v2/Git-内部原理-传输协议</a></span></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">四.3张图了解Git工作原理</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" color="#dc2d1e" heading="2" images="%5B%7B%22ow%22%3A1153%2C%22oh%22%3A829%2C%22id%22%3A%22e16282569fb1126%22%2C%22uri%22%3A%22document_image%2F76245223-3942-44fd-85f4-79aa9cf50dec-747865.jpg%22%7D%5D" style="color: rgb(220, 45, 30); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">一).Git 是一套内容寻址 (content-addressable) 文件系统</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/76245223-3942-44fd-85f4-79aa9cf50dec-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">工作区：.git文件夹所在的目录下的所有范围都是工作区(除了.git文件夹外)</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">暂存区：执行git add &lt;file&gt;后，对象暂时存放的区域，是工作区和本地仓库的桥梁</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">本地版本库：.git文件夹==&gt;Git仓库的核心所在，存放了所有数据版本的变更</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">远程版本库：与当前仓库有绑定管理的xxx.git文件目录 <span class="tag" style="text-decoration: underline; opacity: 0.6; color: inherit;">#一般会由一个中心服务器来担当</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读《Git对象模型》：<a class="content-link" target="_blank" rel="noreferrer" href="http://gitbook.liuhui998.com/1_2.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://gitbook.liuhui998.com/1_2.html</a></span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" color="#dc2d1e" heading="2" images="%5B%7B%22ow%22%3A952%2C%22oh%22%3A983%2C%22id%22%3A%221551628257bb39146%22%2C%22uri%22%3A%22document_image%2F2fae69d7-d9c4-4dd7-874b-13a9571fb24e-747865.jpg%22%7D%5D" style="color: rgb(220, 45, 30); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">二).Git引用：的分支(本地、远程)、标签、HEAD、暂存区(index -- add)、储藏(stash)、对象(tree/blob/commit/tag)的存储......这些都是引用，都是一串SHA1字符串</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/2fae69d7-d9c4-4dd7-874b-13a9571fb24e-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 28px;"><span class="content mubu-node" color="#333333" heading="2" style="color: rgb(51, 51, 51); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">*新版本的 Git 不再使用&nbsp;branches&nbsp;目录，description&nbsp;文件仅供 GitWeb 程序使用*</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v2/Git-%E5%86%85%E9%83%A8%E5%8E%9F%E7%90%86-Git-%E5%BC%95%E7%94%A8" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/book/zh/v2/Git-内部原理-Git-引用</a></span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" color="#dc2d1e" heading="2" images="%5B%7B%22ow%22%3A997%2C%22oh%22%3A464%2C%22id%22%3A%22f3162b504883d084-747865%22%2C%22uri%22%3A%22document_image%2Fbf250bc8-110e-4660-a0fd-85dbfb4c356b-747865.jpg%22%7D%5D" style="color: rgb(220, 45, 30); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">三).Git中文件的生命周期</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/bf250bc8-110e-4660-a0fd-85dbfb4c356b-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="https://www.jianshu.com/p/96beaf505865" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.jianshu.com/p/96beaf505865</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读： <a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v2/Git-基础-记录每次更新到仓库" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/book/zh/v2/Git-基础-记录每次更新到仓库</a></span></li></ul></li><li style="line-height: 28px;"><span class="content mubu-node" color="#dc2d1e" heading="2" style="color: rgb(220, 45, 30); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">获取一个提交对象的信息：git cat-file -p &lt;commitID | tag&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">获取一个blob对象的信息：git show &lt;blobSHA-1&gt;</span></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">五.Git 常用操作</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">1.仓库</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">克隆远程仓库：git clone [-o origin] [-b master] [--depth 1] git@gitlab.com:winz_mmc/mmc_php.git [dir] ==&gt; 当仓库过大时，可以指定克隆分支与深度</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">创建裸仓库：git init --bare xxx.git ==&gt; 自我创建仓库进行学习</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">远程仓库：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看远程仓库信息：git remote -v 查看当前仓库所绑定的远程信息详细信息【fetch | pull】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">获取远程仓库URL:git remote get-url &lt;remote&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">添加远程仓库：git remote add &lt;remote_name&gt; &lt;remote url&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">重命名远程仓库：git remote rename &lt;old&gt; &lt;new&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">修改远程仓库URL:git remote set-url &lt;remote_name&gt; &lt;new_url&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除远程仓库： git remote remove &lt;remote_name&gt;</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">本地仓库：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">拉取本地仓库所有分支的最新远程信息：git pull --all</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推送当前分支到远程并设置默认追踪：git push -u &lt;remote&gt; &lt;local_branch&gt;:&lt;remote_branch&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看当前分支与远程分支相差的log详细信息：git log &lt;remote/branch&gt;..&lt;branch&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">清除本地无效的远程分支：git fetch -p --all</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">标签引用</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">在指定版本号上打上标签：git tag &lt;tag_name&gt; &lt;commit&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">将标签推送给远程仓库：git push --tag</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">2.分支</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">创建并追踪分支：git branch -t &lt;branch_name&gt; &lt;remote/branch&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">创建并检出：git checkout -b &lt;branch_name&gt; [-t(设置追踪)] [HEAD |commitID]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">切换分支：git checkout &lt;branch_name&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">重命名分支：git branch -m &lt;old_branch_name&gt; &lt;new_branch_name&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除本地分支：git branch -D &lt;branch_name&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除远程分支：git push &lt;remote&gt; :&lt;remote_branch&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看所有分支的最后一个提交：git branch -a -v</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">合并：<a class="content-link" target="_blank" rel="noreferrer" href="http://yanhaijing.com/git/2017/07/14/four-method-for-git-merge/" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://yanhaijing.com/git/2017/07/14/four-method-for-git-merge/</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看所有分支git branch -a -v</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">获取所有分支(本地+远程)：git branch -a</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除除当前分支外的所有本地分支：git branch | grep -v '*' | while read branch; do git branch -D $branch; done</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除所有已经merge到master的分支：git branch --merged master | grep -v '^\*\|  master' | xargs -n 1 git branch -d</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">设置分支追踪：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">git branch --set-upstream-to=&lt;origin&gt;/&lt;branch&gt; &lt;local_branch&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">git branch -u &lt;remote/branch&gt; [HEAD|&lt;branche_name&gt;]</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">3.工作区</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">只暂存已经追踪了文件：git add -u </span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">交互式分块暂存： git add -p &lt;file&gt;【<a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/docs/git-add" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/docs/git-add</a>】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除工作区与版本库中的文件：git rm &lt;file&gt;【删除文件及索引 == rm file +git add file】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">强制删除：git rm -f &lt;file&gt;【当文件有未提交的缓存区修改时，直接使用git rm 文件会报错】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除文件在版本库的记录但留存在工作区(该文件将不再被跟踪)：git rm --cached &lt;file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">重命名文件：git mv &lt;old_file&gt; &lt;new_file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看当前工作区和暂存区状态：git status</span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">4.暂存区</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查阅</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看当前暂存区commit信息:git ls-files --stage</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">显示冲突的文件：git ls-files -u [git status -s]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">显示标记为冲突已解决的文件：git ls-files -s</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">提交</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">提交暂存区信息：git commit -m "message"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">修改最后一次提交变更：git commit --amend -m "message"</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">储藏</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">储藏工作区与暂存区文件：git stash save -u "message"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">储藏当前文件，并保留暂存区文件：git stash save --keep-index</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">交互式部分储藏：git stash -p</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除储藏栈指定记录：git stash drop stash@{num}</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看当前储藏栈列表：git stash list</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">应用指定储藏：git stash apply stash@{num} 【git stash pop -- 默认stash@{0}】 </span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">基于指定储藏记录创建分支：git stash branch &lt;branch_name&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">写完代码，发现不在对应分支：①git stash save -u "message";②git checkout &lt;branch_name&gt;;③git stash pop【*stash不要用太多，只是用于临时存储*】</span></span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">5.合并</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">"变更集"合并 -- merge</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A506%2C%22oh%22%3A286%2C%22id%22%3A%2285162b57db3ed10c-747865%22%2C%22uri%22%3A%22document_image%2F7f6d3110-392a-47fc-9866-63417ea993ce-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">合并其他分支代码：git merge &lt;other_branch&gt;【允许快进式合并，如果有冲突则产生新提交】</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/7f6d3110-392a-47fc-9866-63417ea993ce-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A310%2C%22oh%22%3A147%2C%22id%22%3A%22c2162b584376a153-747865%22%2C%22uri%22%3A%22document_image%2Fbef94cd6-1c62-4938-8aa3-9bd3f24b6e87-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">强制非快进式合并：git merge dev --no--ff</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/bef94cd6-1c62-4938-8aa3-9bd3f24b6e87-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A800%2C%22oh%22%3A422%2C%22id%22%3A%223d0162b5c4cf45187-747865%22%2C%22uri%22%3A%22document_image%2Fc3ee0ff0-c75c-4490-bdd9-dc1aee4545b9-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">使用squash方式合并，把多次分支commit历史压缩为一次：git merge &lt;branch&gt; --squash</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/c3ee0ff0-c75c-4490-bdd9-dc1aee4545b9-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">注意：该操作合并之后需要额外commit一次</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">坑：这种方式合并不会讲删除操作合并进来【在"黄色分支"执行git rm file1然后commit,在蓝色分支使用square方式合并，并不会删除file1】</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">当有冲突时：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">停止当前merge操作：git merge --abort</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">继续当前merge操作：git merge --continue</span></li></ul></li></ul></li><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">"变基"合并 -- rebase</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" images="%5B%7B%22ow%22%3A613%2C%22oh%22%3A320%2C%22id%22%3A%222da162b589fed30cd-747865%22%2C%22uri%22%3A%22document_image%2F3175d29d-5e8e-433a-a746-e148c5d852ac-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">将当前分支【feature】以补丁的方式在指定分支上重演合并一次：git rebase &lt;other_branch&gt;</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/3175d29d-5e8e-433a-a746-e148c5d852ac-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">继续当前变基操作【已经解决了当前冲突】：git-rebase --continue </span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">停止当前变基操作【停止后，"和平分手"】：git-rebase --abort</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">丢弃本地冲突的commit继续当前变基操作【高危操作】：git-rebase --skip</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">修改当前编辑操作： git-rebase --edit-todo</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">rebase黄金法则：绝不要在公共的分支上使用它！！！==&gt;rebase操作会将当前分支的改动提交信息全部置顶提交！！</span></span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" images="%5B%7B%22ow%22%3A1534%2C%22oh%22%3A798%2C%22id%22%3A%22f2162b59c7330013-747865%22%2C%22uri%22%3A%22document_image%2Fdfb59265-38e1-4251-86a6-1607ca38a9bd-747865.jpg%22%7D%5D" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">比如说，如果你在develop分支上，rebase到你的feature分支上会发生什么？</span></span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/dfb59265-38e1-4251-86a6-1607ca38a9bd-747865.jpg" style="max-width: 720px;" class="attach-img"></div><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">1. rebase会将当前分支(Develop分支)上的所有的改动提交都"重新演进一次",并将其作为一个新的"补丁方式"的提交移到了feature分支后==&gt;但该改变"仅仅"还在你本地发生的，其他人还在Develop分支上做着改动！</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">2.因为rebase引起了新的提交，Git会认为你的develop分支和其他人的develop已经分叉了，而要同步两个develop分支的唯一办法是把它们merge到一起，这就导致了："一个额外的合并提交"和"两堆包含同样更改的提交"，让人感到莫名其妙！</span></span></li></ul></li></ul></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">自由选择合并点--"摘樱桃模式"：git cherry-pick commitID</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="https://www.cnblogs.com/kidsitcn/p/5339382.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.cnblogs.com/kidsitcn/p/5339382.html</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="http://www.cnblogs.com/ludashi/p/8213550.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://www.cnblogs.com/ludashi/p/8213550.html</a> </span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">6.如何在 Git 里撤销(几乎)任何操作撤销</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A955%2C%22oh%22%3A410%2C%22id%22%3A%223c1162b84996020cc%22%2C%22uri%22%3A%22document_image%2Fbf5504c3-1fd5-404c-bb36-d80ac75906e6-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git撤销示意图</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/bf5504c3-1fd5-404c-bb36-d80ac75906e6-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">1.代码已经push到中心仓库"公共分支"上：git revert &lt;commitID&gt;【严禁采用reset代码再push -f，会覆盖掉别人代码的~】</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.更改"最近一次"提交且代码"没有推到公共分支"：git commit --amend [-m &lt;message&gt;]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.代码还在工作区，没进行git add 操作：git checkout HEAD &lt;file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4.代码已经进行add操作，但是没进行commit操作</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">撤销暂存区修改并保存到工作区：git reset HEAD &lt;file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">撤销丢弃"所有文件"修改： git reset HEAD --hard</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">5.已经进行commit操作，但是还没有push</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">撤销丢弃已经commit的操作：git reset HEAD^ --hard</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">撤销commit操作并留存在暂存区：git reset HEAD^ --soft</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">6.撤销N久的一个操作：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">①git log --pretty=oneline，找到对应的commitID，然后git revert commitID</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">②git reflog【能找到git log没有的信息，但有时限】，找到对应commitID再revert</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="http://blog.jobbole.com/87700/" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://blog.jobbole.com/87700/</a></span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">7.git中所有(几乎)忽略文件的方式：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">已跟踪文件：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">使用.gitignore文件忽略未跟踪文件【整个项目组都要同步的忽略】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">全局忽略：git&nbsp;config&nbsp;--global&nbsp;core.excludesfile&nbsp;path/global_gitignore_file【例如vender目录】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">个人暂时忽略未跟踪文件，不需要同步到中心仓库：vi .git/info/exclude文件&nbsp;</span></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">已经跟踪的文件：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">忽略：git update-index --assume-unchanged FILE</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">解除忽略：git update-index --no-assume-unchanged FILE</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">update-index使用场景：①针对对象是已跟踪文件；②暂时忽略跟踪；③在为解除忽略并同步过信息前强制推送会导致严重的覆盖后果</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">8.差异比较【只会比较跟踪(git add)了的文件】</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">比较当前工作区和暂存区的不同：git diff</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">比较指定文件在工作区和暂存区的不同：git diff &lt;file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">比较暂存区和仓库的不同：git diff --cached</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">比较指定文件在暂存区和仓库的不同：git diff --cached &lt;file&gt;</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">比较任意两个引用：git diff &lt;commit1&gt; &lt;commit2&gt;【分支|tag|commit都是特定SHA1的"引用"】</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">比较版本变化时, 只高亮行内改动, 而非整行：git diff --word-diff</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">只显示有差异的文件，不显示具体信息：git diff --stat</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">忽略空白变更比较：git diff -w</span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">9.查看提交历史&amp;&amp;重写提交历史</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读《git log详解》：<a class="content-link" target="_blank" rel="noreferrer" href="https://www.cnblogs.com/gbyukg/archive/2011/12/12/2285419.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.cnblogs.com/gbyukg/archive/2011/12/12/2285419.html</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看"短期"内，当前本地仓库所有执行的git命令及变化：git reflog</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">数据维护：<a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v1/Git-内部原理-维护及数据恢复" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/book/zh/v1/Git-内部原理-维护及数据恢复</a></span></li></ul></li><li style="line-height: 24px;"><span class="content mubu-node" color="#dc2d1e" heading="3" style="color: rgb(220, 45, 30); line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">重写提交历史</span></span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">交互式选择合并：git rebase -i &lt;commitID&gt;【&lt;remote/branch&gt;也是代表一个特殊的commitID】</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">p, pick = use commit</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">r, reword = use commit, but edit the commit message</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">e, edit = use commit, but stop for amending</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">s, squash = use commit, but meld into previous commit</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">推荐阅读：</span><a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v1/Git-工具-重写历史" style="text-decoration: underline; opacity: 0.6; color: inherit;"><span class="bold" style="font-weight: bold;">https://git-scm.com/book/zh/v1/Git-工具-重写历史</span></a></span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">10.git模块化探索：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">1.使用情景：项目会越来越多，需要提取公共的类库提供给多个项目使用</span></li><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">2.什么是Submodule：git Submodule&nbsp;允许子项目做为一个单独的git项目存在父项目中，子项目有自己完全独立的git操作权限，而父项目以Submodule的形式包含子项目，父项目可以指定子项目header，父项目中会的提交信息包含Submodule的信息，再clone父项目的时候可以把Submodule初始化</span></li><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">3.Submodule操作</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">添加子模块：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">①直接在父项目中添加：git submodule add &lt;remote_url&gt; [ &lt;dir&gt; ] [-b &lt;branch&gt;]</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看子模块状态：git submodule status [&lt;sub_name&gt;]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">更新子模块</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">命令：git submodule foreach "git submodule update"</span></li><li style="line-height: 24px;"><span class="content mubu-node" heading="3" style="line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">注意：先更新子模块，再更新主仓库</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A634%2C%22oh%22%3A422%2C%22id%22%3A%228e162b7e552cf09a-747865%22%2C%22uri%22%3A%22document_image%2Fd2647aaa-ae2a-415f-93cc-87b1a28c5960-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除子模块</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/d2647aaa-ae2a-415f-93cc-87b1a28c5960-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">克隆子模块</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">参数方式：git clone -b dev parent.git parent-sub --recurse-submodules</span></li></ul></li></ul></li><li style="line-height: 24px;"><span class="content mubu-node" color="#dc2d1e" heading="3" style="color: rgb(220, 45, 30); line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">父项目中的变化</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A365%2C%22oh%22%3A75%2C%22id%22%3A%22f4162b7cffac7005-747865%22%2C%22uri%22%3A%22document_image%2F08cf1606-2eaa-430e-8994-7e0eb5a35627-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.多了.gitsubmodule文件</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/08cf1606-2eaa-430e-8994-7e0eb5a35627-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A450%2C%22oh%22%3A626%2C%22id%22%3A%22342162b7d17423135-747865%22%2C%22uri%22%3A%22document_image%2F8d98ab32-5a5d-49a8-a40d-9a81ded59dfd-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.父项目.git文件夹中多了module目录</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/8d98ab32-5a5d-49a8-a40d-9a81ded59dfd-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.每次在子模块中更新后，都需要在父项目中进行额外的commit操作</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：<a class="content-link" target="_blank" rel="noreferrer" href="https://segmentfault.com/a/1190000003076028" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://segmentfault.com/a/1190000003076028</a> </span></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" heading="2" style="line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">11.使用git进行debug</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">查看文件n1-n2行最后的改动信息：git blame -L &lt;n,m&gt; &lt;file&gt;</span></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">"二分法"调试</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">调试开始：git bisect start</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">结束调试：git bisect reset</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">设置good版本起点/终点：git bisect good [&lt;commitID&gt;【默认是HEAD】]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">设置bad版本起点/终点：git bisect good [&lt;commitID&gt;【默认是HEAD】]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">输出调试log历程：git bisect log</span></li></ul></li></ul></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">六.工作流程规范建议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" color="#dc2d1e" heading="2" style="color: rgb(220, 45, 30); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">工作流程介绍</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" images="%5B%7B%22ow%22%3A800%2C%22oh%22%3A345%2C%22id%22%3A%221aa162b05f985c11d%22%2C%22uri%22%3A%22document_image%2Fca8c786b-f217-4e22-aff7-38a34930b3c3-747865.jpg%22%7D%5D" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">集中式工作流【大部分公司应该都是这种方式】</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/ca8c786b-f217-4e22-aff7-38a34930b3c3-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" images="%5B%7B%22ow%22%3A800%2C%22oh%22%3A267%2C%22id%22%3A%22310162b0614c5b013-747865%22%2C%22uri%22%3A%22document_image%2F7d8da82a-3712-4b1d-8db9-bf2b1b76ee1b-747865.jpg%22%7D%5D" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">集成管理者工作流【开源项目的协作方式，开发者自行fork仓库，然后请求管理者拉取更新】</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/7d8da82a-3712-4b1d-8db9-bf2b1b76ee1b-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" images="%5B%7B%22ow%22%3A800%2C%22oh%22%3A412%2C%22id%22%3A%22123162b0637cd0147-747865%22%2C%22uri%22%3A%22document_image%2F1493e163-bdde-4321-81f3-79385abbdddc-747865.jpg%22%7D%5D" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">司令官与副官工作流【就是在集成管理者工作流之上又加了一层管理者，适用庞大的项目=&gt;Linux】</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/1493e163-bdde-4321-81f3-79385abbdddc-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li></ul></li><li style="line-height: 28px;"><span class="content mubu-node" color="#ffaf38" heading="2" style="color: rgb(255, 175, 56); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">分支策略：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li class="collapsed" style="line-height: 24px;"><span class="content mubu-node collapsed" color="#dc2d1e" heading="3" style="color: rgb(220, 45, 30); line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">分支名规则【创建分支时，底层会执行git check-ref format进行强制检查】：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">分支名不能以减号"-"开头【"-"是git命令选项参数的选择标识】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">使用斜杠"/"分层的分支名不能以点"."开头</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">分支名中不能包含连续的两个点"." [连续的两个点是有特殊意义的，代表分支区间]</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">分支名中不能包含任何空格与其他空白字符、ASCII码控制字符、Git中有特殊意义的字符：~ ^ : ? * [</span></li></ul></li><li class="collapsed" style="line-height: 24px;"><span class="content mubu-node collapsed" color="#797ec9" heading="3" style="color: rgb(121, 126, 201); line-height: 24px; min-height: 24px; font-size: 18px; display: inline-block; vertical-align: top;">ERC分支规范对比与建议</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A700%2C%22oh%22%3A369%2C%22id%22%3A%22173162b05666e00b7-747865%22%2C%22uri%22%3A%22document_image%2Fba9f3bbd-fda7-45fd-8fd4-e7d40c1b34cc-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">ERC：master【稳定分支】，dev/develop【开发分支--相当于废了】，feature分支【修bug、日期发布、】、个人开发分支【全拼...】==&gt;乱、分支多所以合并后的"提交树"非常扭曲，你想一下如果你看到下面这样的分支提交信息，作何感想？如果出了问题需要revert，你要怎么找到你的commit信息？</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/ba9f3bbd-fda7-45fd-8fd4-e7d40c1b34cc-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">建议：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A369%2C%22oh%22%3A505%2C%22id%22%3A%22114162b8685572024-747865%22%2C%22uri%22%3A%22document_image%2Faf2cfccb-3457-4d19-8f8e-b6ae182f7a2c-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">使用斜杠"/"对分支进行分类命名，不要全部都用feature-xxx</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/af2cfccb-3457-4d19-8f8e-b6ae182f7a2c-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">master -- 稳定发布分支【理论上master的代码是可以保证随时发布到线上】</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">dev/develop -- 开发分支（目前处于废弃状态）【可进行提交历史整合，用于保证master的提交清晰、明了】==&gt;前后端应该是一致的或者是统一的，保证新建日期发布分支时的依赖是正确的</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">dev-pre-release 预发布分支（目前没有，预发布环境直接用master）；==&gt; 起源于master，回归到master</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">个人分支:personal/xxx（姓名全拼）；==&gt;起源于dev，回归到dev或"日期发布分支"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">补丁分支：hotfix/xxx（修复功能点）；==&gt;起源于master，回归到"预发布"或master</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Bug修复分支：bugfix(或者issue)/xxx（修复功能点）;==&gt;起源于dev，回归到dev或日期发布分支</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">功能/需求分支：feature/xxxx（功能名）</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">日期发布分支：release/xxx（当天发版日期）;==&gt;起源于master，回归到预发布或dev分支</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" images="%5B%7B%22ow%22%3A654%2C%22oh%22%3A536%2C%22id%22%3A%22280162b3c3f57a047-747865%22%2C%22uri%22%3A%22document_image%2Fff6c46c9-02e8-4991-ba60-f7d0aace73fb-747865.jpg%22%7D%5D" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">用完的分支一定要及时删除：(1).分支太多比较乱；(2).代码过于陈旧，提交的时候目前99%会有冲突的【因为现在我们的迭代速度太快了】</span></span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/ff6c46c9-02e8-4991-ba60-f7d0aace73fb-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">预发布不应该"等"所有人代码都没问题再从日期分支直接合并到预发布！！！可以让测试通知已经可以预发布的开发人员合并代码到预发布~</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#333333" style="color: rgb(51, 51, 51); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">为什么要倡导"规范"？当协作的人员越来越多的时候，能更加有效的避免代码冲突、避免提交树的杂乱无章、减小回滚成本</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 28px;"><span class="content mubu-node collapsed" color="#75c940" heading="2" style="color: rgb(117, 201, 64); line-height: 28px; min-height: 28px; font-size: 21px; display: inline-block; vertical-align: top;">为什么每个人都应该写好自己的commit信息？</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1. 提供更多的历史信息，方便快速浏览</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2. 可以过滤某些commit（比如文档改动），便于快速查找信息【commit信息即项目的change log】</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3. 可读性好，清晰，不必深入看代码即可了解当前commit的作用</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4. 为 Code Reviewing做准备</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">5. 方便跟踪工程历史</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">6. 方便进行git revert commitID操作</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">7. 方便通过git来进行debug时的操作</span></li><li style="line-height: 22px;"><span class="content mubu-node" color="#75c940" style="color: rgb(117, 201, 64); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">8. 提高整体项目质量与人工素质</span></li></ul></li><li style="line-height: 22px;"><span class="content mubu-node" color="#dc2d1e" style="color: rgb(220, 45, 30); line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><span class="bold" style="font-weight: bold;">**预发布不应该"等"所有人代码都没问题再从日期分支直接合并到预发布！！！可以让测试通知已经可以预发布的开发人员合并代码到预发布~</span></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：工作流程：<a class="content-link" target="_blank" rel="noreferrer" href="https://git-scm.com/book/zh/v2/分布式-Git-分布式工作流程" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://git-scm.com/book/zh/v2/分布式-Git-分布式工作流程</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：如何写好commit：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="https://segmentfault.com/a/1190000009048911" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://segmentfault.com/a/1190000009048911</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="https://www.cnblogs.com/ctaodream/p/6066694.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.cnblogs.com/ctaodream/p/6066694.html</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="https://chris.beams.io/posts/git-commit/" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://chris.beams.io/posts/git-commit/</a></span></li></ul></li><li class="collapsed" style="line-height: 22px;"><span class="content mubu-node collapsed" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：分支规范：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="https://kb.cnblogs.com/page/132209/" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://kb.cnblogs.com/page/132209/</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;"><a class="content-link" target="_blank" rel="noreferrer" href="http://www.ruanyifeng.com/blog/2012/07/git.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://www.ruanyifeng.com/blog/2012/07/git.html</a></span></li></ul></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">七.工具推荐：GitKraken！</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">1.GitKraken跨平台，官方提供了Linux、Mac、Windows的安装与支持；SourceTree只有Mac、Windows</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">2.GitKraken主题比SourceTree好看【定制主题】、直观、友好~</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">3.GitKraken操作比SourceTree简单容易上手~</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">4.GitKraken有“一键撤销”功能--Undo！</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">5.GitKraken内置冲突查看工具，能更加高效的帮助你解决合并冲突！【以上优点仅仅是"GitKraken"免费版的有点】</span></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A1114%2C%22oh%22%3A460%2C%22id%22%3A%223d5162b3fb9f630ad-747865%22%2C%22uri%22%3A%22document_image%2F2012a71e-898e-4c14-a0f7-cb4edf459c9d-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">GitKraken按键说明：</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/2012a71e-898e-4c14-a0f7-cb4edf459c9d-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22ow%22%3A1384%2C%22oh%22%3A651%2C%22id%22%3A%22281162b3f3a9e315e-747865%22%2C%22uri%22%3A%22document_image%2F516d7dfb-dda1-4fbb-a3b0-f7dd3c72477d-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">SourceTree按键说明：</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/516d7dfb-dda1-4fbb-a3b0-f7dd3c72477d-747865.jpg" style="max-width: 720px;" class="attach-img"></div></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">八.推荐阅读技巧拓展：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">git基础： <a class="content-link" target="_blank" rel="noreferrer" href="https://backlog.com/git-tutorial/cn/" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://backlog.com/git-tutorial/cn/</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">如何在终端显示当前Git分支：<a class="content-link" target="_blank" rel="noreferrer" href="http://blog.csdn.net/Summer_Dream_Journey/article/details/50214609" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://blog.csdn.net/Summer_Dream_Journey/article/details/50214609</a> </span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git迅速提升的10个技巧：<a class="content-link" target="_blank" rel="noreferrer" href="https://www.oschina.net/translate/10-tips-git-next-level?cmp" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.oschina.net/translate/10-tips-git-next-level?cmp</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Show git branches by date：<a class="content-link" target="_blank" rel="noreferrer" href="http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches" style="text-decoration: underline; opacity: 0.6; color: inherit;">http://www.commandlinefu.com/commands/view/2345/show-git-branches-by-date-useful-for-showing-active-branches</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git深度使用经验总结：<a class="content-link" target="_blank" rel="noreferrer" href="https://blog.csdn.net/kangear/article/details/13169395" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://blog.csdn.net/kangear/article/details/13169395</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">推荐阅读：图解Git:<a class="content-link" target="_blank" rel="noreferrer" href="https://www.cnblogs.com/cheneasternsun/p/5952830.html" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://www.cnblogs.com/cheneasternsun/p/5952830.html</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">多语言大改funticon.php或mso_funciont.php文件：<a class="content-link" target="_blank" rel="noreferrer" href="https://segmentfault.com/q/1010000000430426" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://segmentfault.com/q/1010000000430426</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">在git中如何保存配置文件：<a class="content-link" target="_blank" rel="noreferrer" href="https://segmentfault.com/q/1010000000778120/a-1020000000778556" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://segmentfault.com/q/1010000000778120/a-1020000000778556</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">git学习实验：<a class="content-link" target="_blank" rel="noreferrer" href="https://learngitbranching.js.org" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://learngitbranching.js.org</a></span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">Git中你不知道的秘密：<a class="content-link" target="_blank" rel="noreferrer" href="https://clarkdo.js.org/git/2015/05/19/57/" style="text-decoration: underline; opacity: 0.6; color: inherit;">https://clarkdo.js.org/git/2015/05/19/57/</a></span></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">九.alias配置[~/.gitconfig]</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">获取提交树日志信息：hist = log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;author:%an%Creset == %C(bold blue)commitor:%cn&gt;%Creset' --abbrev-commit</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">获取本地仓库所有分支最后一次提交时间：lb = !"for k in `git branch|perl -pe s/^..//`;do echo `git show --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset\" $k|head -n 1`\\\t$k;done|sort"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">删除本地除当前外所有分支：del-branch-a = !"for branch in `git branch |grep -v '*' `;do git branch -d $branch;done"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">检出远程所有分支到本地：</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">&nbsp;cho-branch-a = !"for remote in `git branch -r|grep -v '\\-&gt;'`;do git branch --track ${remote#origin/} $remote;done"</span></li><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">*git branch -r | grep -v '\-&gt;' | while read remote; do git branch --track ${remote#origin/} $remote; done*</span></li></ul></li></ul></li><li class="collapsed" style="line-height: 32px;"><span class="content mubu-node collapsed" heading="1" style="line-height: 32px; min-height: 32px; font-size: 24px; display: inline-block; vertical-align: top;">欢迎打赏与交流</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">以上所有命令皆在git version 2.14.1.windows下试验无误！如遇版本问题，自行搜一下就好！邮箱：lms.minsonlee@gmail.com</span><ul class="children" style="list-style: disc outside; padding-bottom: 4px;"><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22w%22%3A257%2C%22ow%22%3A600%2C%22oh%22%3A900%2C%22id%22%3A%22d3162b882eb2b0ef%22%2C%22uri%22%3A%22document_image%2Fcafb8418-054d-4f47-b548-616a0bc9fb36-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">支付宝打赏</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/cafb8418-054d-4f47-b548-616a0bc9fb36-747865.jpg" style="max-width: 720px; width: 257px;" class="attach-img"></div></li><li style="line-height: 22px;"><span class="content mubu-node" images="%5B%7B%22w%22%3A264%2C%22ow%22%3A1152%2C%22oh%22%3A1152%2C%22id%22%3A%22191162b883174117e%22%2C%22uri%22%3A%22document_image%2F4fc8ee65-c1e7-45ce-ac86-a06cc81b4201-747865.jpg%22%7D%5D" style="line-height: 22px; min-height: 22px; font-size: 14px; display: inline-block; vertical-align: top;">微信打赏</span><div style="padding: 3px 0"><img src="https://img.mubu.com/document_image/4fc8ee65-c1e7-45ce-ac86-a06cc81b4201-747865.jpg" style="max-width: 720px; width: 264px;" class="attach-img"></div></li></ul></li></ul></li></ul></div>
<div style="text-align: center; font-size: 13px"><span style="color: #666"><br/><br/><br/><br/>以上内容整理于 </span><a target="_blank" style="color: #4694FF" href="https://mubu.com?s=export-html">幕布</a></div>
</body>
</html>